package com.erHuo.common.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created by djx on 2017/6/2.
 */
public class userInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {
        // TODO Auto-generated method stub
        HttpSession session = request.getSession();
        System.out.println("pre------" + System.nanoTime());
        if(session.getAttribute("acctuser")!=null){
            return true;
        }else{
            response.sendRedirect("/");
            return false;
        }
    }

    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        System.out.println("after------" + System.nanoTime());
        // TODO Auto-generated method stub

    }

    public void postHandle(HttpServletRequest request,
                           HttpServletResponse response, Object handler,
                           ModelAndView modelAndView) throws Exception {
        System.out.println("post------" + System.nanoTime());
    }

}